const mongoose = require('../util/db')
const userSchema = mongoose.Schema({
    userName:String,
    pwd:String//这里别写错了  搞了半天没把密码存入数据库  一脸懵逼  怎么看都应该对了的
    //前前后后看了Model controller层的数据 都是对的  中间答应的pwd也有    存不进去就算因为这里的pwd写成了ped.
})
const Users = mongoose.model('users',userSchema)
const userInsert = ({userName,pwd})=>{
    const user = new Users({userName,pwd})
    return new Promise((resolve,reject)=>{
        user.save((err,doc)=>{
            if(err) reject()
            else resolve(doc)
        })
    })
}

const searchUser = (userName)=>{
    return new Promise((resolve,reject)=>{
        Users.find(userName,(err,docs)=>{
            if(err) reject()
            else resolve(docs)
        })
    })
}
module.exports={
    userInsert,
    searchUser
}